package com.edu.study.base.commonController;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.edu.common.provice.domain.Province;
import com.edu.common.provice.service.IProvinceService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.uuid.IdUtils;

/**
 * 获取省份数据Controller
 * 
 * @author zw
 * @date 2021-02-01
 */
@RestController
@RequestMapping("/province")
public class ProvinceController extends BaseController
{
    @Autowired
    private IProvinceService provinceService;

    /**
     * 查询获取省份数据列表
     */
    @PreAuthorize("@ss.hasPermi('systemsetup:province:list')")
    @GetMapping("/list")
    public TableDataInfo list(Province province)
    {
        startPage();
        List<Province> list = provinceService.selectProvinceList(province);
        return getDataTable(list);
    }

    /**
     * 导出获取省份数据列表
     */
    @PreAuthorize("@ss.hasPermi('systemsetup:province:export')")
    @Log(title = "获取省份数据", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Province province)
    {
        List<Province> list = provinceService.selectProvinceList(province);
        ExcelUtil<Province> util = new ExcelUtil<Province>(Province.class);
        return util.exportExcel(list, "province");
    }

    /**
     * 获取获取省份数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('systemsetup:province:query')")
    @GetMapping(value = "/{provCode}")
    public AjaxResult getInfo(@PathVariable("provCode") String provCode)
    {
        return AjaxResult.success(provinceService.selectProvinceById(provCode));
    }

    /**
     * 新增获取省份数据
     */
    @PreAuthorize("@ss.hasPermi('systemsetup:province:add')")
    @Log(title = "获取省份数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Province province)
    {
        province.setProvCode(IdUtils.simpleUUID());
        return toAjax(provinceService.insertProvince(province));
    }

    /**
     * 修改获取省份数据
     */
    @PreAuthorize("@ss.hasPermi('systemsetup:province:edit')")
    @Log(title = "获取省份数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Province province)
    {
        return toAjax(provinceService.updateProvince(province));
    }

    /**
     * 删除获取省份数据
     */
    @PreAuthorize("@ss.hasPermi('systemsetup:province:remove')")
    @Log(title = "获取省份数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{provCodes}")
    public AjaxResult remove(@PathVariable String[] provCodes)
    {
        return toAjax(provinceService.deleteProvinceByIds(provCodes));
    }
}
